#!/usr/bin/env python
# coding: utf-8

# In[ ]:


import pandas as pd
from snownlp import SnowNLP
import matplotlib.pyplot as plt
import numpy as np

df = pd.read_excel('D://music_163.xlsx')

# 提取评论内容
comments = df['comments'].tolist()

# 开始情感分析
scores = []
for comment in comments:
    s = SnowNLP(comment)
    score = s.sentiments
    scores.append(score)
#     print(f"Comment: {comment} | Score: {score}")

# 可视化情感分析结果---直方图
plt.rcParams['font.sans-serif'] = ['SimHei']  
plt.rcParams['axes.unicode_minus'] = False   # 显示负号
plt.hist(scores, bins=60, facecolor='g')
plt.xlabel('情感评分', size=12)
plt.ylabel('数量', size=12)
plt.title('热评情感分析', color="blue", size=12)
plt.show()

